/*******************************************************************************
* Project: QSAR(Cute Software Architecture) 
*
* Copyright: Copyright(C) 2024 by YuetingBen, All Rights Reserved
*
* File name: DcmDslCfg.h
*
* Brief: ;
*
* Author: Yueting.Ben
*
* Module: DCMDSL
*
* Revision:
* --------------------------------------------------------------------------------
* v0.1: 
* --Yueting.Ben, 2024-03-11 
* --Initial release

**********************************************************************************/
#ifndef DCMDSLCFG_H
#define DCMDSLCFG_H

/** HEADER FILES **/
#include "DcmType.h"
#include "DcmCfg.h"
#include "DcmRte.h"
#include "DcmDslType.h"
#include "DcmDsdCfg.h"


/** MACRO DEFINITION **/
#define DCM_DSL_PROTOCAL_MAX_RES_SIZE     100
#define DCM_DSL_RES_PEND_MAX_RES_SIZE     3


/** TYPEDEF DEFINITION **/
typedef struct
{
    void* txPduPtr; /* DcmDslProtocolTxPduRef */
    uint16 txConfirmationPduId; /* DcmDslTxConfirmationPduId */
}DcmDslProtocolTxType;


typedef struct
{
    void* rxPduPtr; /* DcmDslProtocolRxPduRef */
    PduIdType rxPduId; /* DcmDslProtocolRxPduId */
    DcmDsl_ProtocolRxAddrType rxAddrType; /* DcmDslProtocolRxAddrType */
}DcmDslProtocolRxType;


typedef struct
{
    uint16 rxConnectionId; /* DcmDslProtocolRxConnectionId */
    void* comMChannelPtr; /* DcmDslProtocolComMChannelRef */
    DcmDslProtocolTxType protocolTx; /* DcmDslProtocolTx */
    DcmDslProtocolRxType protocolRx; /* DcmDslProtocolRx */
}DcmDslMainConnectionType;


typedef struct
{
    uint16 periodicTxConfirmationPduId; /*  DcmDslPeriodicTxConfirmationPduId */
}DcmDslPeriodicTransmissionType;


typedef struct
{
    DcmDslMainConnectionType mainConnection; /* DcmDslMainConnection  */
    DcmDslPeriodicTransmissionType periodicConnection; /* DcmDslPeriodicTransmission   */
}DcmDslConnectionType;


typedef uint8 DcmDslProtocolTypeType; /* DcmDslProtocolType */


typedef struct
{
    DcmDslConnectionType connection; /* DcmDslConnection */
    Dcm_SvcCfgType*  serviceTable; /* DcmDsdServiceTable */
    Dcm_MsgType rxBufferPtr; /* DcmDslProtocolRxBufferRef */
    Dcm_MsgType txBufferPtr; /* DcmDslProtocolTxBufferRef */
    
    uint16 ecuAddr; /* DcmDspProtocolEcuAddr */
    uint16 maximumResponseSize; /* DcmDslProtocolMaximumResponseSize     */

    /* Thisparameter isusedtoguaranteethatthediagnosticresponseisavailableonthe
         busbeforereachingP2byadjustingthecurrentDcmDspSessionP2ServerMax.
         Thisparametermainlyrepresentsthesoftwarearchitecturedependentcommunication
         delaybetweenthetimethetransmissionisinitiatedbyDCMandthetimewhenthe
         messageisactuallytransmittedtothebus.
         TheparametervalueisdefinedinsecondsandmustbeamultipleofDcmTaskTime. 
         Unit:ms, range[0-1000] */
    uint16 DcmTimStrP2ServerAdjust;
    /* This parameter is used to guarantee that the diagnostic response is available on the
        bus before reaching P2Star by adjusting the current DcmDspSessionP2StarServerMax
        The parameter value is defined in seconds and must be a multiple of DcmTaskTime
        Unit:ms, range[0-5000] */
    uint16 DcmTimStrP2StarServerAdjust;

    /* If set to TRUE, the Dcm will send a NRC 0x78 before a transition to bootloader or performing an ECU reset. 
        If set to False, no 0x78 is send in this case. */
    uint8 DcmSendRespPendOnRestart; /*   DcmSendRespPendOnRestart */
}DcmDslProtocolRowType;


typedef struct
{
    DcmDslProtocolRowType protocolRow[DcmConf_DcmRxPduCfg_Pdu_Max]; /* DcmDslProtocolRow   */
}DcmDslProtocolType;

typedef struct
{
    /* Maximumnumberofnegativeresponseswithresponsecode0x78(requestCorrectlyReceivedResponsePending)allowedforarequest */
    uint8 DcmDslDiagRespMaxNumRespPend;
}DcmDslDiagRespType;


/** LOCAL DATA DEFINITION **/
extern Dcm_MsgItemType Dcm_DslBuffer[DCM_DSL_PROTOCAL_MAX_RES_SIZE];
extern Dcm_MsgItemType Dcm_DslDiagResp[DCM_DSL_RES_PEND_MAX_RES_SIZE];
extern DcmDslProtocolType DcmDslProtocolCfg;


#endif
